<?php
namespace Ptime3\Functions;
use Pheanstalk\Pheanstalk;

class Queue
{
	public static function put($tube, $data){
		$logData = ["time"=>date("Y-m-d H:i:s"),"tube"=>$tube,"data"=>$data];
		file_put_contents("../storage/logs/queue_".date("Ymd").".txt",json_encode($logData)."\r\n", FILE_APPEND);

		$env = function_exists("env")?env("APP_ENV"):"dev";
		if($env == "product"){
			$queueHost = env("MQ_HOST");
		}else{
			$queueHost = "192.168.2.103";
		}

		$pheanstalk = new Pheanstalk($queueHost);
		return $pheanstalk->useTube($tube)->put(json_encode($data),0,0);
	}
}